All Questions
Tagged with programming-practiceslanguage-agnostic
31 questions
8votes
5answers
983views
Is it bad practice to add "false or" or "true and" to conditionals?
Is it bad practice to add false or ... or true and ... for the sake of promoting code genericness and/or ease of use? As in: SELECT * FROM table WHERE TRUE AND IsEnabled AND SomeField = some_value ...
3votes
3answers
770views
Why is it better to use parameters instead of temporary global variables?
If you're a very old programmer like me you may have written stuff like this early on: DIM A, B, C LET A = 2 LET B = 2 GOSUB ADD PRINT C END ADD: LET C = A + B RETURN (Actually, if you're an assembly ...
0votes
2answers
110views
Negation of sameness is confirmation of difference [closed]
De Morgan's laws: the negation of a disjunction is the conjunction of the negations; and the negation of a conjunction is the disjunction of the negations; or, the same: not (A or B) = not A and not B;...
2votes
1answer
293views
Guard block moved to the bottom [closed]
Sometimes it is a good idea to have a guard block: https://softwareengineering.stackexchange.com/a/157413 https://en.wikipedia.org/wiki/Guard_(computer_science) Guard block guards against special ...
1vote
4answers
3kviews
What should be the last entry in a switch/case statement?
When writing a switch statement that only ever has to deal with a known set of values (imagine an implicit enumeration), I find myself wondering what should be the last entry in the construct. I'm ...
6votes
5answers
498views
Does only the concept of mathematical functions justify why methods need only to return one value
Most modern programming languages do not allow multiple return types (excluding scenarios like C#'s out parameters or the newest use of Tuples). This is because all languages implement the concept of ...
1vote
2answers
3kviews
What's the correct way of computing money in programming (precision, repeating decimal) [duplicate]
This is the first time I'll be writing an application (personal) that involves money computation. One of the potential issues I found is with regards to precision and repeating decimal. Ex. 1 / 3 = ...
5votes
5answers
560views
Should I ignore features of one language when I plan to port my code to another which doesn't have such features?
I'm currently toying around with a very large project. A interpreter for a simple scripting language. After weeks of planning, I decided that the best course of action would be to prototype part of ...
7votes
3answers
685views
What is the procedure(if any) to select bytes to represent opcodes?
TL;DR What procedure is followed when selecting bytes to represent opcodes? Are byte(s) for opcodes just randomly chosen, and them mapped to mnemonics? I recently learned from this answer that ...
1vote
1answer
160views
What is the best way to incorporate new language features into your code? [closed]
My main language is currently JavaScript, and I'd say I'm fairly proficient in it. That is, when I think "I want to do x", I don't (generally) Google "how to do x", but I think "I know! I will use ...
34votes
7answers
4kviews
Arguments against error suppression
I've found a piece of code like this in one of our projects: SomeClass QueryServer(string args) { try { return SomeClass.Parse(_server.Query(args)); } ...
7votes
6answers
2kviews
Is it an overkill to write unit tests for a small code base? [duplicate]
I am the sole maintainer of a code base of about 2000 lines of code. It's not big, but over time the code became so unmaintainable my boss agreed to give me time to rewrite it from scratch. Since the ...
17votes
6answers
2kviews
Writing comments for some small code with rather large background [duplicate]
So I had to write some code related to splitting Bezier curves into parts. I read through several references and particularly referred this rather detailed one. The final code outcome is however ...
3votes
2answers
229views
What is a proper way to chain instructions if previous one is ok [duplicate]
I'm currently working on a big file I have to parse and process and each step needs to be done in an order as I do SQL queries and need inserted IDs to make other insertions ... The problem is I often ...
93votes
7answers
17kviews
Short circuit evaluation, is it bad practice?
Something that I've known for a while but never considered is that in most languages it is possible to give priority to operators in an if statement based on their order. I often use this as a way to ...